//
//  MyButton.m
//  项目A_百思不得姐
//
//  Created by wudongyang on 16/6/7.
//  Copyright © 2016年 wudongyang. All rights reserved.
//

#import "MyButton.h"
#define imageRatio 0.8
@implementation MyButton

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        // 保持图片原比例在视图中间显示图片
        self.imageView.contentMode = UIViewContentModeCenter;
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 图片
    CGFloat imageW = self.bounds.size.width;
    CGFloat imageH = self.bounds.size.height * imageRatio;
    CGFloat imageY = 0;
    CGFloat imageX = 0;
    self.imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
    
    // 文字
    CGFloat titleX = 0;
    CGFloat titleY = imageH;
    CGFloat titleH = self.bounds.size.height - titleY;
    self.titleLabel.frame = CGRectMake(titleX, titleY, imageW, titleH);
    
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [UIView animateWithDuration:0.25 animations:^{
        // 放大为原始的1.2倍
        self.transform = CGAffineTransformMakeScale(1.2, 1.2);
    }];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    // 放大为原始的2倍,最后消失
    [UIView animateWithDuration:0.25 animations:^{
        
        self.transform = CGAffineTransformMakeScale(2, 2);
        
        self.alpha = 0;
        
    } completion:^(BOOL finished) {
        
    }];
    
    
}

@end
